import axios from "@/utils/http";
import { AnyColumn } from "element-plus/es/components/table-v2/src/common";
//数据
const state = {
  //数据定义处
  tableData:[],
  tableTotal:1,
  proName:[]
};

const getters = {
  //修饰后的数据获取方法
  getProjectData(state:any){
    return state.tableData
  },
  getOption(state:any){
    let arr = <any>[]
    state.proName.forEach((item:any) => {
        arr.push({
          value:item.projectName,
          label:item.projectName
        })
    });

    return arr;

  }
};

const mutations = {
  //修改数据处 ，可在这写axios请求拿数据
  // 分页获取全部数据
  setProjectData(state:any,page:any){
    axios({
      url: "/setting/SystemInspection/fundInspections",
      method:"get",
      params:{
        currentPage:page.currentPage,
        pageSize:page.pageSize
      }
      }).then((res:any)=>{
        console.log("检查项目",res.data.data);
        state.tableData=res.data.data
        console.log(res.data.count);
        
        state.tableTotal=res.data.count
        console.log(state.tableTotal);
        
          // state.XXX=res.data.data
     }).catch(err=>{
      console.log(err);
     })
    
  },

  // 删除数据
  delProjectData(state:any,row:any){
    console.log("删除",row.id);
    axios({
      url: "/setting/SystemInspection/deltInspection",
      method:"post",
      params:{
        id:row.id
      }
      }).then((res:any)=>{
        console.log("删除项目",res.data);
        // state.tableData=res.data.data
        // state.tableTotal=res.data.count
        // console.log(state.tableTotal);
        
          // state.XXX=res.data.data
     }).catch(err=>{
      console.log(err);
     })
  },

  // 搜索数据
  searchProjectData(state:any,search:any){
   console.log( search.serachValue);
    axios({
      url: "/setting/SystemInspection/fundInspection",
      method:"get",
      params:{
        currentPage:search.currentPage,
        pageSize:search.pageSize,
        itemName:search.serachValue
      }
      }).then((res:any)=>{
        console.log("搜索",res.data.data);
        state.tableData=res.data.data
        state.tableTotal=1

     }).catch(err=>{
      console.log(err);
     })

  },
  // 编辑拿取项目
editProjectData(state:any){
  axios({
    url: "/setting/SystemInspection/fundprojectss",
    method:"get",
    params:{
      
    }
    }).then((res:any)=>{
      console.log("编辑",res.data.data);
      state.proName=res.data.data
      console.log(state.proName);
      
      // state.tableData=res.data.data
      // state.tableTotal=res.data.count
      // console.log(state.tableTotal);
      
        // state.XXX=res.data.data
   })
   .catch(err=>{
    console.log(err);
   })
},
// 编辑保存接口
saveProjectData(state:any,data:any){
  console.log("qweqweqw",data.id);
  axios({
    url: "/setting/SystemInspection/editInspection",
    method:"post",
    data:{
      "id":data.id,
      "itemName": data.itemName,
        "itemType": data.itemType,
        "itemPrice": data.itemPrice,
        "itemCost": data.itemCost,
    }
    }).then((res:any)=>{
      console.log("保存数据",res.data);
   })
   .catch(err=>{
    console.log(err);
   })
},

// 新增接口
addProjectData(state:any,data:any){
 
  axios({
    url: "/setting/SystemInspection/addInspection",
    method:"post",
    data:{
      "itemName": data.itemName,
   "itemType": data.itemType,
   "itemPrice": data.itemPrice,
   "itemCost":data.itemCost,
    }
    }).then((res:any)=>{
      console.log("新增数据",res.data);
   })
   .catch(err=>{
    console.log(err);
   })


  
}
};


const actions = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
